package com.qin.mall.controller.productcontroller;

import com.qin.mall.common.api.CommonResult;
import com.qin.mall.domain.PmsSkuStock;
import com.qin.mall.openfeign.product.SkuStockFeigin;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author Leisure
 * create 2022 2022/11/19 19:18
 **/
@RestController
@RequestMapping("/sku")
public class StockController {
    
    @Autowired
    private SkuStockFeigin stockFeigin;

    //根据产品id和skuCode模糊搜索
    @GetMapping("/{pid}")
    public CommonResult<List<PmsSkuStock>> getStock(@PathVariable Long pid,
                                                    @RequestParam(value = "keyword",required = false) String keyword){
        CommonResult<List<PmsSkuStock>> stock = stockFeigin.getStock(pid, keyword);
        return stock;
    }

    //更新库存
    @PostMapping("/update/{pid}")
    public CommonResult updateStock(@PathVariable Long pid,
                                    @RequestBody List<PmsSkuStock> skuStockList){
        CommonResult result = stockFeigin.updateStock(pid,skuStockList);
        return result;
    }

}
